<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>定时任务</title>
    <meta name="description" content="e-shop">
    <meta name="keywords" content="e-shop">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>系统设置<small>定时任务</small></h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>系统设置</el-breadcrumb-item>
            <el-breadcrumb-item>定时任务</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <div class="filter-container">
                <el-switch
                        style="display: block"
                        v-model="taskValue"
                        active-color="#13ce66"
                        inactive-color="#ff4949"
                        active-text="开启"
                        inactive-text="关闭"
                        @change="taskChange">
                </el-switch>
            </div>
            <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                <el-table-column type="index" align="center" label="序号"></el-table-column>
                <el-table-column prop="operation" label="操作" align="center"></el-table-column>
                <el-table-column prop="operTime" label="操作时间" align="center"></el-table-column>
            </el-table>
            <div class="pagination-container">
                <el-pagination
                        class="pagiantion"
                        @current-change="handleCurrentChange"
                        :current-page="pagination.pageNum"
                        :page-size="pagination.pageSize"
                        layout="total, prev, pager, next, jumper"
                        :total="pagination.total">
                </el-pagination>
            </div>
        </div>
    </div>
</div>
</body>
<!-- 引入组件库 -->
<script src="../js/vue.js"></script>
<script src="../plugins/elementui/index.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<script>
    var vue = new Vue({
        el: '#app',
        data: {
            pagination: {//分页相关模型数据
                pageNum: 1,//当前页码
                pageSize: 8,//每页显示的记录数
                total: 0//总记录数
            },
            taskValue: true,//定时任务
            formData: {},//表单数据
        },
        //钩子函数，VUE对象初始化完成后自动执行
        created() {
            this.findPage();//VUE对象初始化完成后调用分页查询方法，完成分页查询
            this.taskHui();
        },
        methods: {
            taskHui() {
                axios.get("/task/newOperation").then(res => {
                    var param = res.data.data.operation;
                    if (param == 1) {
                        this.taskValue = true;
                    } else {
                        this.taskValue = false;
                    }

                });
            },
            taskChange(taskValue) {
                if (taskValue) {
                    //为true 是开启定时任务
                    this.taskValue = 1;
                } else {
                    this.taskValue = 0;
                }
                axios.get("/task/job?taskValue=" + this.taskValue).then(res => {
                    this.findPage();
                    this.taskHui();
                });
            },
            //分页查询
            findPage() {
                //发送ajax请求，提交分页相关请求参数（页码、每页显示记录数、查询条件）
                var param = {
                    pageNum: this.pagination.pageNum,
                    pageSize: this.pagination.pageSize
                };
                axios.post("/task/list", param).then((res) => {
                    //解析Controller响应回的数据，为模型数据赋值
                    this.pagination.total = res.data.data.total;
                    // alert(res.data.msg)
                    this.dataList = res.data.data.list;
                });
            },
            // 重置表单
            resetForm() {
                this.formData = {};//重置数据
            },
            //切换页码
            handleCurrentChange(pageNum) {
                //设置最新的页码
                this.pagination.pageNum = pageNum;
                //重新调用findPage方法进行分页查询
                this.findPage();
            },
        }
    })
</script>
</html>